//
//  LoginTools.m
//  ThunderChat
//
//  Created by Kelly xu on 2018/11/13.
//  Copyright © 2018 Simubang. All rights reserved.
//

#import "LoginTools.h"
#import "LoginInfoModel.h"
#import "UserManager.h"
@implementation LoginTools
+(LoginTools*)sharedTools{
    static LoginTools *_shared = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _shared = [[LoginTools alloc] init];
    });
    return _shared;
}
-(void)saveUserInfo:(NSDictionary*)userInfo{
    self.token = [userInfo objectForKey:@"token"];
    self.appkey = [userInfo objectForKey:@"appKey"];
    self.userId = [[userInfo objectForKey:@"userInfo"] objectForKey:@"id"];
    LoginInfoModel *model = [[LoginInfoModel alloc]init];
    model.token = [userInfo objectForKey:@"token"];
    model.appkey = [userInfo objectForKey:@"appKey"];
    model.userId = [[userInfo objectForKey:@"userInfo"] objectForKey:@"id"];
    [UserManager saveUerInfoWithModel:model];
}
-(void)removeUserInfo{
    [UserManager clearUserInfo];
}
-(NSString*)token{
    LoginInfoModel *model = [UserManager readUserInfo];
    return EC_ISNullStr(model.token)?@"":model.token;
}
-(NSString*)appkey{
    LoginInfoModel *model = [UserManager readUserInfo];
    return EC_ISNullStr(model.appkey)?@"":model.appkey;
}
-(NSString*)userId{
    LoginInfoModel *model = [UserManager readUserInfo];
    return EC_ISNullStr(model.userId)?@"":model.userId;
}
@end
